home *** CD-ROM | disk | FTP | other *** search
/ Aminet 24 / Aminet 24 (1998)(GTI - Schatztruhe)[!][Apr 1998].iso / Aminet / dev / lang / PPCSmllEiffel.lha / PPCSmallEiffel / lib_se / short_print.e < prev    next >
Text File  |  1998-01-16  |  7KB  |  349 lines

  1. --          This file is part of SmallEiffel The GNU Eiffel Compiler.
  2. --          Copyright (C) 1994-98 LORIA - UHP - CRIN - INRIA - FRANCE
  3. --            Dominique COLNET and Suzanne COLLIN - colnet@loria.fr 
  4. --                       http://www.loria.fr/SmallEiffel
  5. -- SmallEiffel is  free  software;  you can  redistribute it and/or modify it 
  6. -- under the terms of the GNU General Public License as published by the Free
  7. -- Software  Foundation;  either  version  2, or (at your option)  any  later 
  8. -- version. SmallEiffel is distributed in the hope that it will be useful,but
  9. -- WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  10. -- or  FITNESS FOR A PARTICULAR PURPOSE.   See the GNU General Public License 
  11. -- for  more  details.  You  should  have  received a copy of the GNU General 
  12. -- Public  License  along  with  SmallEiffel;  see the file COPYING.  If not,
  13. -- write to the  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  14. -- Boston, MA 02111-1307, USA.
  15. --
  16. class SHORT_PRINT
  17.    --
  18.    -- Driver for the `short' command.
  19.    --
  20.  
  21. inherit GLOBALS;
  22.  
  23. creation make
  24.  
  25. feature {NONE}
  26.  
  27.    format_directory: STRING;
  28.      -- For the output style.
  29.  
  30.    base_class: BASE_CLASS;
  31.      -- The one printed.
  32.  
  33.    run_class: RUN_CLASS;
  34.      -- The one printed.
  35.  
  36. feature {NONE}
  37.  
  38.    make is
  39.       do
  40.       end;
  41.    
  42. feature {SHORT}
  43.  
  44.    start(format: STRING; bc: BASE_CLASS; rc: RUN_CLASS) is
  45.       local
  46.      hc2: COMMENT;
  47.      fgl: FORMAL_GENERIC_LIST;
  48.       do
  49.      base_class := bc;
  50.      run_class := rc;
  51.      -- Setting `format_directory' :
  52.      format_directory := small_eiffel_directory.twin;
  53.      add_directory(format_directory,"short");
  54.      add_directory(format_directory,format);
  55.      -- Start output :
  56.      hook("hook000");
  57.      if bc.is_expanded then
  58.         hook_or("hook010","expanded class interface ");
  59.      elseif bc.is_deferred then
  60.         hook_or("hook011","deferred class interface ");
  61.      else
  62.         hook_or("hook012","class interface ");
  63.      end;
  64.      hook("hook013");
  65.      a_class_name(bc.base_class_name);
  66.      fgl := bc.formal_generic_list;
  67.      if fgl /= Void then
  68.         fgl.short;
  69.      end;
  70.      hook_or("hook014","%N");
  71.      hc2 := bc.heading_comment2;
  72.      if hc2 /= Void then
  73.         hook("hook015");
  74.         hc2.short("hook016","   -- ","hook017","%N");
  75.         hook("hook018");
  76.      else
  77.         hook("hook019");
  78.      end;
  79.       end;
  80.  
  81.    finish is
  82.       local
  83.      fgl: FORMAL_GENERIC_LIST;
  84.      ci: CLASS_INVARIANT;
  85.       do
  86.      ci := run_class.invariant_assertion;
  87.      if ci = Void then
  88.         hook("hook800");
  89.      else
  90.         ci.short(base_class);
  91.      end;
  92.      hook("hook900");
  93.      if base_class.is_expanded then
  94.         hook_or("hook901","end of expanded ");
  95.      elseif base_class.is_deferred then
  96.         hook_or("hook902","end of deferred ");
  97.      else
  98.         hook_or("hook903","end of ");
  99.      end;
  100.      hook("hook904");
  101.      a_class_name(base_class.base_class_name);
  102.      fgl := base_class.formal_generic_list;
  103.      if fgl /= Void then
  104.         fgl.short;
  105.      end;
  106.      hook_or("hook905","%N");
  107.      hook("hook999");
  108.       end;
  109.  
  110. feature
  111.  
  112.    hook_or(h, str: STRING) is
  113.       do
  114.      if hook_exists(h) then
  115.         from
  116.            tmp_hook.read_character;
  117.         until
  118.            tmp_hook.end_of_input
  119.         loop
  120.            std_output.put_character(tmp_hook.last_character);
  121.            tmp_hook.read_character;
  122.         end;
  123.         tmp_hook.disconnect;
  124.      else
  125.         std_output.put_string(str);
  126.      end;
  127.       end;
  128.  
  129.    hook(h: STRING) is
  130.       do
  131.      if hook_exists(h) then
  132.         from
  133.            tmp_hook.read_character;
  134.         until
  135.            tmp_hook.end_of_input
  136.         loop
  137.            std_output.put_character(tmp_hook.last_character);
  138.            tmp_hook.read_character;
  139.         end;
  140.         tmp_hook.disconnect;
  141.      end;
  142.       end;
  143.  
  144.    a_class_name(name: CLASS_NAME) is
  145.       local
  146.      i: INTEGER;
  147.      c: CHARACTER;
  148.      str: STRING;
  149.       do
  150.      hook("Bcn");
  151.      from
  152.         str := name.to_string;
  153.         i := 1;
  154.      until
  155.         i > str.count
  156.      loop
  157.         c := str.item(i);
  158.         if c = '_' then
  159.            hook_or("Ucn","_");
  160.         else
  161.            std_output.put_character(c);
  162.         end;
  163.         i := i + 1;
  164.      end;
  165.      hook("Acn");
  166.       end;
  167.  
  168.    a_feature(fn: FEATURE_NAME) is
  169.      -- Where `fn' is really the final name to print.
  170.       local
  171.      rf: RUN_FEATURE;
  172.       do
  173.      rf := run_class.get_feature(fn);
  174.      a_run_feature(rf);
  175.       end;
  176.  
  177.    a_run_feature(rf: RUN_FEATURE) is
  178.       local
  179.      args: FORMAL_ARG_LIST;
  180.      rt: TYPE;
  181.      hc: COMMENT;
  182.      rr: RUN_REQUIRE;
  183.      ea: E_ENSURE;
  184.       do
  185.      hook_or("hook300","   ");
  186.      rf.name.short;
  187.      args := rf.arguments;
  188.      if args = Void then
  189.         hook_or("hook301","");
  190.      else
  191.         args.short;
  192.      end;
  193.      rt := rf.result_type;
  194.      if rt = Void then
  195.         hook_or("hook307","%N");
  196.      else
  197.         hook_or("hook308",": ");
  198.         rt.short;
  199.         hook_or("hook309","%N");
  200.      end;
  201.      -- *******
  202.      hc := rf.base_feature.header_comment;
  203.      if hc /= Void then
  204.         hook("hook310");
  205.         hc.short("hook311","      -- ","hook312","%N");
  206.         hook("hook313");
  207.      else
  208.         hook("hook314");
  209.      end;
  210.      rr := rf.require_assertion;
  211.      if rr = Void then
  212.         hook("hook400");
  213.      else
  214.         rr.short;
  215.      end;
  216.      ea := rf.ensure_assertion;
  217.      if ea = Void then
  218.         hook_or("hook500","");
  219.      else
  220.         ea.short;
  221.      end;
  222.      hook_or("hook599","");
  223.       end;
  224.  
  225.    a_integer(value: INTEGER) is
  226.       local
  227.      s: STRING;
  228.      c: CHARACTER;
  229.      i: INTEGER;
  230.       do
  231.      s := "";
  232.      s.clear;
  233.      value.append_in(s);
  234.      from
  235.         i := 1;
  236.      until
  237.         i > s.count
  238.      loop
  239.         c := s.item(i);
  240.         std_output.put_character(c);
  241.         i := i + 1;
  242.      end;
  243.       end;
  244.  
  245.    a_character(c: CHARACTER) is
  246.       do
  247.      std_output.put_character(c);
  248.       end;
  249.  
  250.    a_dot is
  251.       do
  252.      hook_or("dot",fz_dot);
  253.       end;
  254.  
  255. feature {CALL_PREFIX}
  256.  
  257.    a_prefix_name(pn: PREFIX_NAME) is
  258.      -- Used in an expression.
  259.       local
  260.      i: INTEGER;
  261.      c: CHARACTER;
  262.      str: STRING;
  263.       do
  264.      from
  265.         str := pn.to_string;
  266.         i := 1;
  267.      until
  268.         i > str.count
  269.      loop
  270.         c := str.item(i);
  271.         if c = '_' then
  272.            hook_or("Usfn","_");
  273.         else
  274.            std_output.put_character(c);
  275.         end;
  276.         i := i + 1;
  277.      end;
  278.      a_character(' ');
  279.       end;
  280.       
  281. feature {CALL_INFIX,INFIX_NAME}
  282.  
  283.    a_infix_name(h1,r1,h2,r2: STRING; in: INFIX_NAME) is
  284.       local
  285.      i: INTEGER;
  286.      str: STRING;
  287.       do
  288.      hook_or(h1,r1);
  289.      str := in.to_string;
  290.      if us_backslash_backslash = str then
  291.         hook_or("rem",us_backslash_backslash);
  292.      else
  293.         from
  294.            i := 1;
  295.         until
  296.            i > str.count
  297.         loop
  298.            std_output.put_character(str.item(i));
  299.            i := i + 1;
  300.         end;
  301.      end;
  302.      hook_or(h2,r2);
  303.       end;
  304.       
  305. feature {BASE_TYPE_CONSTANT}
  306.  
  307.    a_base_type_constant(str: STRING) is
  308.       local
  309.      i: INTEGER;
  310.      c: CHARACTER;
  311.       do
  312.      from
  313.         i := 1;
  314.      until
  315.         i > str.count
  316.      loop
  317.         c := str.item(i);
  318.         if c = '.' then
  319.            hook_or("dot",".");
  320.         else
  321.            std_output.put_character(c);
  322.         end;
  323.         i := i + 1;
  324.      end;
  325.       end;
  326.  
  327. feature {NONE}
  328.  
  329.    hook_exists(h: STRING): BOOLEAN is
  330.       do
  331.      tmp_hook_path.copy(format_directory);
  332.      tmp_hook_path.append(h);
  333.      tmp_hook.connect_to(tmp_hook_path);
  334.      Result := tmp_hook.is_connected;
  335.       end;
  336.  
  337.    tmp_hook: STD_FILE_READ is
  338.       once
  339.      !!Result.make;
  340.       end;
  341.  
  342.    tmp_hook_path: STRING is
  343.       once
  344.      !!Result.make(80);
  345.       end;
  346.  
  347. end -- SHORT_PRINT
  348.  
  349.